package com.ymatou.iapi.userservice.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.userservice.parameter.QueryTPBindByOpenIdBean;
import com.ymatou.iapi.userservice.parameter.enums.AppSourceEnum;
import com.ymatou.iapi.userservice.parameter.req.BindThirdPartyUserReq;
import com.ymatou.iapi.userservice.parameter.req.CreateThirdPartyUserReq;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.service.QueryTPBindByOpenIdCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
/**
*根据OpenId查询获取第三方用户绑定关系
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_QueryTPBindByOpenId{
	private static QueryTPBindByOpenIdBean querytpbindbyopenidBean;
	private static QueryTPBindByOpenIdCall querytpbindbyopenidCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据OpenId查询获取第三方用户绑定关系");
	}

	@Before
	public void caseUp() {
		querytpbindbyopenidBean=new QueryTPBindByOpenIdBean();
		querytpbindbyopenidCall=new QueryTPBindByOpenIdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(querytpbindbyopenidCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryTPBindByOpenId_001() {
		Logger.start(true,"根据OpenId查询获取第三方用户绑定关系成功");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			JUserCallService.bindThirdPartyUserCall(bd);
			querytpbindbyopenidBean.setOpenId(bd.getOpenId());
			querytpbindbyopenidCall.setData(querytpbindbyopenidBean);
			querytpbindbyopenidCall.callService();			
			Logger.verifyEquals("200", querytpbindbyopenidCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("true", querytpbindbyopenidCall.getString("Success"), "验证Success");
			JsonObject Result = querytpbindbyopenidCall.getJsonObject().get("Result").getAsJsonObject();
			
			Logger.verifyEquals(bd.getThirdPartyId(), Result.get("thirdPartyId").getAsString(), "验证thirdPartyId");
			Logger.verifyEquals(bd.getThirdPartyType().getCode().toString(), Result.get("thirdPartyType").getAsString(), "验证thirdPartyType");
			Logger.verifyEquals(bd.getAppSource().getCode().toString(), Result.get("appSource").getAsString(), "验证thirdPartyId");
			Logger.verifyEquals(bd.getOpenId().toString(), Result.get("openId").getAsString(), "验证openId");
			Logger.verifyEquals(uid.toString(), Result.get("userId").getAsString(), "验证userId");
			Logger.verifyNotNull(Result.get("createTime").toString(), "验证createTime");
			Logger.verifyNotNull(Result.get("registerTime").toString(), "验证registerTime");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryTPBindByOpenId_002() {
		Logger.start(true,"不输入openid失败");
		try {
//			querytpbindbyopenidBean.setOpenId(bd.getOpenId());
			querytpbindbyopenidCall.setData(querytpbindbyopenidBean);
			querytpbindbyopenidCall.callService();			
			Logger.verifyEquals("100", querytpbindbyopenidCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("false", querytpbindbyopenidCall.getString("Success"), "验证Success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryTPBindByOpenId_003() {
		Logger.start(true,"输入openid不存在失败");
		try {
			querytpbindbyopenidBean.setOpenId("-111");
			querytpbindbyopenidCall.setData(querytpbindbyopenidBean);
			querytpbindbyopenidCall.callService();			
			Logger.verifyEquals("200", querytpbindbyopenidCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("true", querytpbindbyopenidCall.getString("Success"), "验证Success");
			Logger.verifyIsNull(querytpbindbyopenidCall.getJsonObject().get("Result"), "验证Result");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryTPBindByOpenId_004() {
		Logger.start(true,"根据OpenId查询获取第三方用户绑定关系成功-GlobalApp");
		try {
			CreateThirdPartyUserReq cur = JUserCallService.initCreateThirdUserReq();
			cur.setAppSource(AppSourceEnum.GlobalApp);
			Integer uid = JUserCallService.createThirdPartyUserCall(cur);
			querytpbindbyopenidBean.setOpenId(cur.getOpenId());
			querytpbindbyopenidCall.setData(querytpbindbyopenidBean);
			querytpbindbyopenidCall.callService();			
			Logger.verifyEquals("200", querytpbindbyopenidCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("true", querytpbindbyopenidCall.getString("Success"), "验证Success");
			JsonObject Result = querytpbindbyopenidCall.getJsonObject().get("Result").getAsJsonObject();
			
			Logger.verifyEquals(cur.getThirdPartyId(), Result.get("thirdPartyId").getAsString(), "验证thirdPartyId");
			Logger.verifyEquals(cur.getThirdPartyType().getCode().toString(), Result.get("thirdPartyType").getAsString(), "验证thirdPartyType");
			Logger.verifyEquals(cur.getAppSource().getCode().toString(), Result.get("appSource").getAsString(), "验证thirdPartyId");
			Logger.verifyEquals(cur.getOpenId().toString(), Result.get("openId").getAsString(), "验证openId");
			Logger.verifyEquals(uid.toString(), Result.get("userId").getAsString(), "验证userId");
			Logger.verifyNotNull(Result.get("createTime").toString(), "验证createTime");
			Logger.verifyNotNull(Result.get("registerTime").toString(), "验证registerTime");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryTPBindByOpenId_005() {
		Logger.start(true,"根据OpenId查询获取第三方用户绑定关系成功-GlobalWxApp");
		try {
			CreateThirdPartyUserReq cur = JUserCallService.initCreateThirdUserReq();
			cur.setAppSource(AppSourceEnum.GlobalWxApp);
			Integer uid = JUserCallService.createThirdPartyUserCall(cur);
			querytpbindbyopenidBean.setOpenId(cur.getOpenId());
			querytpbindbyopenidCall.setData(querytpbindbyopenidBean);
			querytpbindbyopenidCall.callService();			
			Logger.verifyEquals("200", querytpbindbyopenidCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("true", querytpbindbyopenidCall.getString("Success"), "验证Success");
			JsonObject Result = querytpbindbyopenidCall.getJsonObject().get("Result").getAsJsonObject();
			
			Logger.verifyEquals(cur.getThirdPartyId(), Result.get("thirdPartyId").getAsString(), "验证thirdPartyId");
			Logger.verifyEquals(cur.getThirdPartyType().getCode().toString(), Result.get("thirdPartyType").getAsString(), "验证thirdPartyType");
			Logger.verifyEquals(cur.getAppSource().getCode().toString(), Result.get("appSource").getAsString(), "验证thirdPartyId");
			Logger.verifyEquals(cur.getOpenId().toString(), Result.get("openId").getAsString(), "验证openId");
			Logger.verifyEquals(uid.toString(), Result.get("userId").getAsString(), "验证userId");
			Logger.verifyNotNull(Result.get("createTime").toString(), "验证createTime");
			Logger.verifyNotNull(Result.get("registerTime").toString(), "验证registerTime");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}